import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number // 表id
  name: number // 地图名
  north: string // 北边地图
  south: string // 南边地图
  east: string // 东边地图
  west: string // 西边地图
  description: string // 地图描述
  map_type: string // 地图类型
  map_level: number // 地图等级
  map_size: string // 地图大小
}

class map_location extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

map_location.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '表id'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '地图名'
    },
    north: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '北边地图'
    },
    south: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '南边地图'
    },
    east: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '东边地图'
    },
    west: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '西边地图'
    },
    description: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '地图描述'
    },
    map_type: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '地图类型'
    },
    map_level: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '地图等级'
    },
    map_size: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '地图大小'
    }
  },
  {
    sequelize,
    tableName: 'map_location',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: false,
        fields: ['id']
      },
      {
        unique: false,
        fields: ['name']
      }
    ]
  }
)

export { map_location }
